#include "widget.h"
#include "ui_widget.h"

class WidgetPrivate
{
    WidgetPrivate(Widget *q)
        : q_ptr(q)
        , m_model(nullptr){}

    ~WidgetPrivate(){}

    Q_DECLARE_PUBLIC(Widget)
    Widget *q_ptr;
    QStandardItemModel *m_model;
};

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    , d_ptr(new WidgetPrivate(this))

{
    ui->setupUi(this);
    this->setWindowTitle("防疫工作检查服务端");

    Q_D(Widget);
    d->m_model = new QStandardItemModel();
    d->m_model->setColumnCount(5);
    d->m_model->setHorizontalHeaderItem(0, new QStandardItem("姓名"));
    d->m_model->setHorizontalHeaderItem(1, new QStandardItem("年龄"));
    d->m_model->setHorizontalHeaderItem(2, new QStandardItem("身份证"));
    d->m_model->setHorizontalHeaderItem(3, new QStandardItem("住址"));
    d->m_model->setHorizontalHeaderItem(4, new QStandardItem("放行状态"));
    ui->tableView->setModel(d->m_model);
    ui->tableView->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
    ui->tableView->setColumnWidth(0, 100);
    ui->tableView->setColumnWidth(1, 100);
    ui->tableView->setColumnWidth(2, 200);
    ui->tableView->setColumnWidth(3, 500);
    ui->tableView->setColumnWidth(4, 100);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::checkTemperature(const QString &name, int age, const QString &id, const QString &address, double dTemperature)
{
    QString status;
    if (dTemperature > 37.2)
    {
        QString msg = QString("%1(%2),今日体温%3异常，隔离！").arg(name).arg(id).arg(dTemperature);
        //QMessageBox::warning(this, "体温检查结果", msg);
        emit signalTemperatureIsOk(false);
        status = "隔离";
    }
    else
    {
        QString msg = QString("%1(%2),今日体温%3正常，放行。").arg(name).arg(id).arg(dTemperature);
        //QMessageBox::information(this, "体温检查结果", msg);
        emit signalTemperatureIsOk(true);
        status = "放行";
    }

    Q_D(Widget);
    int curRow = d->m_model->rowCount();
    d->m_model->setItem(curRow, 0, new QStandardItem(name));
    d->m_model->setItem(curRow, 1, new QStandardItem(QString::number(age)));
    d->m_model->setItem(curRow, 2, new QStandardItem(id));
    d->m_model->setItem(curRow, 3, new QStandardItem(address));
    d->m_model->setItem(curRow, 4, new QStandardItem(status));
}
